﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter06
{
    public class Code02
    {
        private static string myString;
        private static int val;

        public static void Begin()
        {
            {
                string myString = "String defined in Main()";
                Code02.myString = "Global string";
                Write();
                Console.WriteLine("\nNow in Main()");
                Console.WriteLine("Local myString = {0}", myString);
                Console.WriteLine("Global myString = {0}", Code02.myString);
                Console.ReadLine();
            }
            {
                int i;
                string text = null;
                for (i = 0; i < 10; i++)
                {
                    text = "Line " + Convert.ToString(i);
                    Console.WriteLine(text);
                }
                Console.WriteLine("Last text output in loop: {0}", text);
                Console.ReadLine();
            }
            {
                int val = 5;
                Console.WriteLine("val = {0}", val);
                ShowDouble(ref val);
                Console.WriteLine("val = {0}", val);
            }
            {
                val = 5;
                Console.WriteLine("val = {0}", val);
                ShowDouble();
                Console.WriteLine("val = {0}", val);
            }
        }

        private static void Write()
        {
            string myString = "String defined in Write()";
            Console.WriteLine("Now in Write();");
            Console.WriteLine("myString = {0}", myString);
        }

        private static void ShowDouble()
        {
            val *= 2;
            Console.WriteLine("val doubled = {0}", val);
        }

        private static void ShowDouble(ref int val)
        {
            val *= 2;
            Console.WriteLine("val doubled = {0}", val);
        }
    }
}
